#!/usr/bin/env python
# -*- coding: utf-8 -*-


import socket

import requests


def get_host_external_ip():
    """
    查询本机外网ip地址
    :return:
    """
    e_host = requests.get('https://checkip.amazonaws.com/', timeout=1).text.strip()

    return e_host


def get_host_intranet_ip():
    """
    查询本机内网ip地址
    :return:
    """
    _s = None
    try:
        _s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        _s.connect(('8.8.8.8', 80))
        i_host = _s.getsockname()[0]
    finally:
        _s.close()

    return i_host


if __name__ == '__main__':
    print(get_host_intranet_ip())
